package au.com.bellygoodengine.DataAccessObject.DAOImpl;

import java.util.List;
import java.util.logging.Logger;

import javax.jdo.PersistenceManager;

import au.com.bellygoodengine.DataAccessObject.AbstractDAO;
import au.com.bellygoodengine.DataAccessObject.PMF;
import au.com.bellygoodengine.DataAccessObject.DAOInterface.IMenuDAO;
import au.com.bellygoodengine.models.Menu;

public class MenuDAO extends AbstractDAO implements IMenuDAO {
	
	private static final Logger log = Logger.getLogger(MenuDAO.class.getName());
	
	@Override
	public void persistMenu(Menu menu) {
		// TODO Auto-generated method stub
		PersistenceManager pm = PMF.get().getPersistenceManager();
        try {
            pm.makePersistent(menu);
        }catch (Exception e) {
        	log.severe(e.toString());
		}  finally {
            pm.close();
        }
	}

	@Override
	public Menu getMenu(long id) {
		return null;
	}

	@Override
	public void deleteMenu(long id) {
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Menu> getAllMenus() {
		PersistenceManager pm = PMF.get().getPersistenceManager();
	    String query = "select from " + Menu.class.getName();
	    List<Menu> menus = null;
	    try {
	    	menus = (List<Menu>) pm.newQuery(query).execute();
        }catch (Exception e) {
        	log.severe(e.toString());
//        	if (tx.isActive()) tx.rollback();
		} finally {
            pm.close();
        }
	    return menus;
	}

}
